import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'node:path'

let version = process.env['VERSION'] || '0.0.0-dev'

export default defineConfig({
  define: {
    __APP_VERSION__: JSON.stringify(version),
    'process.env.NODE_ENV': '"production"',
  },

  build: {
    lib: {
      entry: resolve(__dirname, 'src/components/lib.ts'),
      name: 'filePicker',
      fileName: 'lzc-file-pickers',
    },
    sourcemap: true,
    rollupOptions: {
      output: {
        dir: 'libs/lzc-file-pickers/dist',
        globals: {
          vue: 'Vue',
          pinia: 'pinia',
        },
      },
    },
  },

  plugins: [
    vue({ customElement: true }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
